package app;

import common.struct.SensorData;

import java.util.*;

public class AppDemoDatabase extends AbstractApp {
    @Override
    public void configApp() {
        this.appName = "AppDemoDatabase";
        this.appDescription = "This is AppDemoDatabase";
    }

    @Override
    public void getMsg(String sensorName, SensorData value) {
        // 因为注册了front传感器，所以每当front有新的数据时便会触发getMsg，
        // 其中channel是sensor名字，msg是sensor数据
        logger.info(String.format("[%s]: getMsg(sensorName, value) -> %s, %s", appName, sensorName, value));
        //用户代码
    }

    public static void main(String[] args) {
        AppDemoDatabase demo = new AppDemoDatabase();
        AppRemoteConnector connector = AppRemoteConnector.getInstance();
        connector.connectPlatform("127.0.0.1", 9090);
        connector.registerApp(demo);

        DBController db = DBController.getInstance();
        db.createTable("test", "id", Arrays.asList("id", "name", "age"), 3);
        db.insertRow("test", Map.of("id", 1, "name", "Tom", "age", 20));
        db.insertRow("test", Map.of("id", 2, "name", "Jerry", "age", 21));
        db.insertRow("test", Map.of("id", 3, "name", "Jack", "age", 22));
        db.insertRow("test", Map.of("id", 4, "name", "Rose", "age", 23));
        db.getAllRows("test");

//        connector.getAllAppInfo();
//        connector.getAllSensorInfo();
//        connector.getAllActorInfo();

        connector.unregisterApp(demo);
        connector.disConnectPlatform();
    }
}
